package com.answer.filter;

import com.answer.utils.Redisutils;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import javax.servlet.*;
import javax.servlet.http.HttpServletRequest;
import java.io.IOException;
import java.util.Arrays;
import java.util.List;

@Order(1)
// @Component
public class WebVisitFilter implements Filter {


    @Resource
    private Redisutils redisutils;

    final private List<String> list = Arrays.asList("/user/ttttt1");

    @Override
    public void init(FilterConfig filterConfig) throws ServletException {
        Filter.super.init(filterConfig);
    }

    @Override
    public void doFilter(ServletRequest servletRequest, ServletResponse servletResponse, FilterChain filterChain) throws IOException, ServletException {

        HttpServletRequest httpServletRequest = (HttpServletRequest) servletRequest;
        String requestURI = httpServletRequest.getRequestURI();
        System.out.println(requestURI);
        System.out.println(redisutils);
        if (list.contains(requestURI)){
            filterChain.doFilter(servletRequest, servletResponse);
        }else {
            System.out.println("WebVisitFilter 执行了");
            filterChain.doFilter(servletRequest, servletResponse);
        }

    }

    @Override
    public void destroy() {
        Filter.super.destroy();
    }
}
